package org.platform.config;

/**
 * Quartz 进行spring管理
 * 使用方法,注入Scheduler即可
 *
 * @author FengJie
 * @date 2018/7/18
 */

import lombok.extern.slf4j.Slf4j;
import org.quartz.Scheduler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;


@Configuration
@Slf4j
public class QuartzConfig {
    @Autowired
    private MyJobFactory myJobFactory;

    @Bean
    public SchedulerFactoryBean schedulerFactoryBean() {
        SchedulerFactoryBean schedulerFactoryBean = new SchedulerFactoryBean();
        log.info("【quartz自定义线程池】初始化【成功】");
        schedulerFactoryBean.setJobFactory(myJobFactory);
        return schedulerFactoryBean;
    }


    @Bean
    public Scheduler scheduler() {
        return schedulerFactoryBean().getScheduler();
    }


}